package com.xcity.game.equip.suit4.impl;

import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.Combat;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.buff.CombatBuffTemplate;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.equip.suit4.BaseSuit4;
import com.xcity.game.equip.template.EquipSuitEffectTemplate;

/**
 * 卡文克莱4件套<br/>
 * 造成伤害时有{20}%的几率增加一名队友{20}点出手速度，持续到战斗结束
 * @author yang.li
 *
 */
public class Suit4CalvinKlein extends BaseSuit4 {

	public Suit4CalvinKlein(CombatUnit unit, EquipSuitEffectTemplate template) {
		super(unit, template);
	}

	@Override
	public void afterDamage0(ActionEffect effect) {
		if (unit.getId() != effect.ref().getUnitId()) {
			return;
		}
		if (Combat.RND.nextInt(GameStaticConfig.percentBase) < template.getSuit4Param(0)) {
			CombatUnit u = unit.getTeam().getUnitRandomly();
			if (u != null && u.getId() != unit.getId()) {
				int speed = (int) (u.getAttackSpeed() + template.getSuit4Param(1));
				CombatBuffTemplate buffTemplate = CombatBuffTemplate.find(5);
				effect.ref().addBuff(new BUFF(buffTemplate, u, speed));
			}
		}
	}
	
	static class BUFF extends CombatBuff {
		public BUFF(CombatBuffTemplate template, CombatUnit owner, int speed) {
			super(template, owner);
			owner.setAttributeValue(CombatAttributeType.ATTACK_SPEED, speed);
		}
	}

}
